home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WW3DKit / WWLightInspectorShape.m < prev    next >
Encoding:
Text File  |  1995-03-22  |  7.5 KB  |  261 lines

  1. // copyright 1993 Michael B. Johnson; some portions copyright 1994, MIT
  2. // see COPYRIGHT for reuse legalities
  3. //
  4.  
  5.  
  6. #import "WWLightInspectorShape.h"
  7.  
  8. @implementation WWLightInspectorShape
  9.  
  10. + initialize { return [WWLightInspectorShape setVersion:1], self; }
  11.  
  12. - setBoundingBox:(RtBound)aBBox
  13. {
  14.   boundingBox[0] = aBBox[0];
  15.   boundingBox[1] = aBBox[1];
  16.   boundingBox[2] = aBBox[2];
  17.   boundingBox[3] = aBBox[3];
  18.   boundingBox[4] = aBBox[4];
  19.   boundingBox[5] = aBBox[5];
  20.   [self synchUpWithBoundingBox];
  21.  
  22.   return self;
  23. }
  24.  
  25. - synchUpWithBoundingBox
  26. {
  27.   xMin = boundingBox[0];
  28.   xMax = boundingBox[1];
  29.   yMin = boundingBox[2];
  30.   yMax = boundingBox[3];
  31.   zMin = boundingBox[4];
  32.   zMax = boundingBox[5];
  33.  
  34.   boxPoints[0][0] = xMin; 
  35.   boxPoints[0][1] = yMin; 
  36.   boxPoints[0][2] = zMin; 
  37.  
  38.   boxPoints[1][0] = xMax; 
  39.   boxPoints[1][1] = yMin; 
  40.   boxPoints[1][2] = zMin; 
  41.  
  42.   boxPoints[2][0] = xMax; 
  43.   boxPoints[2][1] = yMax; 
  44.   boxPoints[2][2] = zMin; 
  45.  
  46.   boxPoints[3][0] = xMin; 
  47.   boxPoints[3][1] = yMax; 
  48.   boxPoints[3][2] = zMin; 
  49.  
  50.   boxPoints[4][0] = xMin; 
  51.   boxPoints[4][1] = yMin; 
  52.   boxPoints[4][2] = zMax; 
  53.  
  54.   boxPoints[5][0] = xMax; 
  55.   boxPoints[5][1] = yMin; 
  56.   boxPoints[5][2] = zMax; 
  57.  
  58.   boxPoints[6][0] = xMax; 
  59.   boxPoints[6][1] = yMax; 
  60.   boxPoints[6][2] = zMax; 
  61.  
  62.   boxPoints[7][0] = xMin; 
  63.   boxPoints[7][1] = yMax; 
  64.   boxPoints[7][2] = zMax; 
  65.  
  66.   ////////////////////////////////////
  67.   ////////// X Axis //////////////////
  68.   ////////////////////////////////////
  69.   // 1st point
  70.   xAxisPoints[0][0] = 0.0;
  71.   xAxisPoints[0][1] = 2.0*yMin;
  72.   xAxisPoints[0][2] = 2.0*zMin;
  73.   //if (yMin < 0.0) { xAxisPoints[0][1] = 2.0*yMin; } else { xAxisPoints[0][1] = yMin/2.0; }
  74.   //if (zMin < 0.0) { xAxisPoints[0][2] = 2.0*zMin; } else { xAxisPoints[0][2] = zMin/2.0; }
  75.   // 2nd point
  76.   xAxisPoints[1][0] = 0.0;
  77.   xAxisPoints[1][1] = 2.0*yMax;
  78.   xAxisPoints[1][2] = 2.0*zMin;
  79.   //if (yMax < 0.0) { xAxisPoints[0][1] = 2.0*yMax; } else { xAxisPoints[1][1] = yMax/2.0; }
  80.   //if (zMin < 0.0) { xAxisPoints[0][2] = 2.0*zMin; } else { xAxisPoints[1][2] = zMin/2.0; }
  81.   // 3rd point
  82.   xAxisPoints[2][0] = 0.0;
  83.   xAxisPoints[2][1] = 2.0*yMax;
  84.   xAxisPoints[2][2] = 2.0*zMax;
  85.   //if (yMax < 0.0) { xAxisPoints[0][1] = 2.0*yMax; } else { xAxisPoints[2][1] = yMax/2.0; }
  86.   //if (zMax < 0.0) { xAxisPoints[0][2] = 2.0*zMax; } else { xAxisPoints[2][2] = zMax/2.0; }
  87.   // 4th point
  88.   xAxisPoints[3][0] = 0.0;
  89.   xAxisPoints[3][1] = 2.0*yMin;
  90.   xAxisPoints[3][2] = 2.0*zMax;
  91.   //if (yMin < 0.0) { xAxisPoints[0][1] = 2.0*yMin; } else { xAxisPoints[3][1] = yMin/2.0; }
  92.   //if (zMax < 0.0) { xAxisPoints[0][2] = 2.0*zMax; } else { xAxisPoints[3][2] = zMax/2.0; }
  93.  
  94.   ////////////////////////////////////
  95.   ////////// Y Axis //////////////////
  96.   ////////////////////////////////////
  97.   // 1st point
  98.   yAxisPoints[0][0] = 2.0*xMin;
  99.   yAxisPoints[0][1] = 0.0;
  100.   yAxisPoints[0][2] = 2.0*zMin;
  101.   //if (xMin < 0.0) { yAxisPoints[0][0] = 2.0*xMin; } else { yAxisPoints[0][0] = xMin/2.0; }
  102.   //if (zMin < 0.0) { yAxisPoints[0][2] = 2.0*zMin; } else { yAxisPoints[0][2] = zMin/2.0; }
  103.   // 2nd point
  104.   yAxisPoints[1][0] = 2.0*xMax;
  105.   yAxisPoints[1][1] = 0.0;
  106.   yAxisPoints[1][2] = 2.0*zMin;
  107.   //if (xMax < 0.0) { yAxisPoints[0][0] = 2.0*xMax; } else { yAxisPoints[1][0] = xMax/2.0; }
  108.   //if (zMin < 0.0) { yAxisPoints[0][2] = 2.0*zMin; } else { yAxisPoints[1][2] = zMin/2.0; }
  109.   // 3rd point
  110.   yAxisPoints[2][0] = 2.0*xMax;
  111.   yAxisPoints[2][1] = 0.0;
  112.   yAxisPoints[2][2] = 2.0*zMax;
  113.   //if (xMax < 0.0) { yAxisPoints[0][0] = 2.0*xMax; } else { yAxisPoints[2][0] = xMax/2.0; }
  114.   //if (zMax < 0.0) { yAxisPoints[0][2] = 2.0*zMax; } else { yAxisPoints[2][2] = zMax/2.0; }
  115.   // 4th point
  116.   yAxisPoints[3][0] = 2.0*xMin;
  117.   yAxisPoints[3][1] = 0.0;
  118.   yAxisPoints[3][2] = 2.0*zMax;
  119.   //if (xMin < 0.0) { yAxisPoints[0][0] = 2.0*xMin; } else { yAxisPoints[3][0] = xMin/2.0; }
  120.   //if (zMax < 0.0) { yAxisPoints[0][2] = 2.0*zMax; } else { yAxisPoints[3][2] = zMax/2.0; }
  121.  
  122.   ////////////////////////////////////
  123.   ////////// Z Axis //////////////////
  124.   ////////////////////////////////////
  125.   // 1st point
  126.   //if (xMin < 0.0) { zAxisPoints[0][0] = 2.0*xMin; } else { zAxisPoints[0][0] = xMin/2.0; }
  127.   //if (yMin < 0.0) { zAxisPoints[0][1] = 2.0*yMin; } else { zAxisPoints[0][1] = yMin/2.0; }
  128.   zAxisPoints[0][0] = 2.0*xMin;
  129.   zAxisPoints[0][1] = 2.0*yMin;
  130.   zAxisPoints[0][2] = 0.0;
  131.   // 2nd point
  132.   //if (xMin < 0.0) { zAxisPoints[0][0] = 2.0*xMin; } else { zAxisPoints[1][0] = xMin/2.0; }
  133.   //if (yMax < 0.0) { zAxisPoints[0][1] = 2.0*yMax; } else { zAxisPoints[1][1] = yMax/2.0; }
  134.   zAxisPoints[1][0] = 2.0*xMin;
  135.   zAxisPoints[1][1] = 2.0*yMax;
  136.   zAxisPoints[1][2] = 0.0;
  137.   // 3rd point
  138.   //if (xMax < 0.0) { zAxisPoints[0][0] = 2.0*xMax; } else { zAxisPoints[2][0] = xMax/2.0; }
  139.   //if (yMax < 0.0) { zAxisPoints[0][1] = 2.0*yMax; } else { zAxisPoints[2][1] = yMax/2.0; }
  140.   zAxisPoints[2][0] = 2.0*xMax;
  141.   zAxisPoints[2][1] = 2.0*yMax;
  142.   zAxisPoints[2][2] = 0.0;
  143.   // 4th point
  144.   //if (xMax < 0.0) { zAxisPoints[0][0] = 2.0*xMax; } else { zAxisPoints[3][0] = xMax/2.0; }
  145.   //if (yMin < 0.0) { zAxisPoints[0][1] = 2.0*yMin; } else { zAxisPoints[3][1] = yMin/2.0; }
  146.   zAxisPoints[3][0] = 2.0*xMax;
  147.   zAxisPoints[3][1] = 2.0*yMin;
  148.   zAxisPoints[3][2] = 0.0;
  149.  
  150.   return self;
  151. }
  152.  
  153. - init
  154. {
  155.   RtBound  aBoundingBox = { -1., 1., -1., 1., -1., 1. }; 
  156.  
  157.   [super init];
  158.  
  159.   boxNVertices[0] = boxNVertices[1] = boxNVertices[2] = boxNVertices[3] = boxNVertices[4] = boxNVertices[5] = 4;
  160.  
  161.   boxVertices[0] = 0;
  162.   boxVertices[1] = 1;
  163.   boxVertices[2] = 2;
  164.   boxVertices[3] = 3;
  165.  
  166.   boxVertices[4] = 1;
  167.   boxVertices[5] = 5;
  168.   boxVertices[6] = 6;
  169.   boxVertices[7] = 2;
  170.  
  171.   boxVertices[8] = 5;
  172.   boxVertices[9] = 6;
  173.   boxVertices[10] = 7;
  174.   boxVertices[11] = 4;
  175.  
  176.   boxVertices[12] = 0;
  177.   boxVertices[13] = 3;
  178.   boxVertices[14] = 7;
  179.   boxVertices[15] = 4;
  180.  
  181.   boxVertices[16] = 3;
  182.   boxVertices[17] = 2;
  183.   boxVertices[18] = 6;
  184.   boxVertices[19] = 7;
  185.  
  186.   boxVertices[20] = 0;
  187.   boxVertices[21] = 1;
  188.   boxVertices[22] = 5;
  189.   boxVertices[23] = 4;
  190.  
  191.   [self setBoundingBox:aBoundingBox];
  192.  
  193.   return self;
  194. }
  195.  
  196.  
  197.  
  198. #define X_AXIS 1.0, 0.0, 0.0
  199. #define Y_AXIS 0.0, 1.0, 0.0
  200. #define Z_AXIS 0.0, 0.0, 1.0
  201. #define    wwMax(a,b)  (((a)>(b))?(a):(b))
  202. #define    wwMin(a,b)  (((a)>(b))?(b):(a))
  203.  
  204. // it's probably worth caching all this info...
  205. //
  206. - renderSelf:(N3DCamera *)camera
  207. {
  208.   // red:   255 81 107 == 1.00  .318 .420 
  209.   // green: 96 215 121 ==  .376 .843 .475
  210.   // blue:  98 124 255 ==  .384 .486 1.00
  211.   RtColor  xColor = { 1.00 ,  .318,  .420 },
  212.            yColor = {  .376,  .843,  .475 },
  213.            zColor = {  .384,  .486, 1.00  };
  214.   RtFloat  xSize, ySize, zSize;
  215.  
  216.  
  217.   [super renderSelf:camera];
  218.  
  219.   // draw the inside box
  220.   RiPointsPolygons(6, boxNVertices, boxVertices, RI_P, boxPoints, RI_NULL);
  221.  
  222.   // draw the xAxis (the yzPlane)
  223.   RiColor(xColor);
  224.   RiPolygon(4, RI_P, xAxisPoints, RI_NULL);
  225.  
  226.   // draw the yAxis (the xzPlane)
  227.   RiColor(yColor);
  228.   RiPolygon(4, RI_P, yAxisPoints, RI_NULL);
  229.  
  230.   // draw the zAxis (the xyPlane)
  231.   RiColor(zColor);
  232.   RiPolygon(4, RI_P, zAxisPoints, RI_NULL);
  233.   // want small cone at zMax
  234.   zSize = zMax - zMin;
  235.   RiTranslate(0, 0, (2*zMax));
  236.   RiCone((.3 * zSize), (.1 * zSize), 360, RI_NULL);
  237.   RiTranslate(0, 0, (-2*zMax));
  238.  
  239.   RiRotate(-90, X_AXIS);
  240.   // rotate about X -90 degrees to be pointing along the Y axis
  241.   RiColor(yColor);
  242.   ySize = yMax - yMin;
  243.   RiTranslate(0, 0, (2*yMax));
  244.   RiCone((.3 * ySize), (.1 * ySize), 360, RI_NULL);
  245.   RiTranslate(0, 0, (-2*yMax));
  246.  
  247.   // rotate about Y 90 degrees to be pointing along the X axis
  248.   RiRotate(90, Y_AXIS);
  249.   RiColor(xColor);
  250.   xSize = xMax - xMin;
  251.   RiTranslate(0, 0, (2*xMax));
  252.   RiCone((.3 * xSize), (.1 * xSize), 360, RI_NULL);
  253.   RiTranslate(0, 0, (-2*xMax));
  254.  
  255.  
  256.   return self;
  257. }
  258.  
  259.  
  260. @end
  261.